﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Popup.Master" AutoEventWireup="true"
    CodeBehind="DocPromotion.aspx.cs" Inherits="PromotionEngine.DocPromotion" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        var isInsert = false;
        var gridBuy;
        var gridGet;
        var docEntry;
        $(document).ready(function () {
            docEntry = <%= Request.QueryString["DocEntry"] %>;
            gridBuy = $("#gridBuy").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "DocPromotion.aspx/GetDocPromotionBuy",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        parameterMap: function (data, operation) {
                            if (operation === "read") {
                                return { docEntry: docEntry };
                            }
                        },
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true
                    },
                    type: "odata", //Important!!!!
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d.Data;
                                return data;
                            }
                        },
                        total: "d.Count",
                        model: {
                            id: "Id",
                            fields: {
                                ID: { type: "string", validation: { required: true} },
                                LinkKey: { type: "string", validation: { required: true} },
                                DocEntry: { type: "string", validation: { required: true} },
                                PromotionID: { type: "string", validation: { required: true} },
                                PromotionCode: { type: "string", validation: { required: true} },
                                PromotionName: { type: "string", validation: { required: true} },
                                ItemID: { type: "string", validation: { required: true} },
                                ItemCode: { type: "string", validation: { required: true} },
                                ItemName: { type: "string", validation: { required: true} },
                                Quantity: { type: "number", validation: { required: true} },
                                BasePrice: { type: "number", validation: { required: true} },
                                DiscountPercent: { type: "number", validation: { required: true} },
                                DiscountAmount: { type: "number", validation: { required: true} },
                                PriceAfterDiscount: { type: "number", validation: { required: true} },
                                TotalAfterDiscount: { type: "number", validation: { required: true} }
                            }
                        }
                    }
                },
                sortable: true,
                filterable: true,
                reorderable: true,
                resizable: true,
                 selectable: "row",
                height: 200,
                excel: {
                    fileName: "Promotion Buy List.xlsx",
                    filterable: true
                },
                batch: true,
                columns: [
                            { field: "ID", title: "ID", width: 100, hidden: true },
                            { field: "LinkKey", title: "LinkKey", width: 60, attributes: { style: "text-align:centrer;"}  },
                            { field: "DocEntry", title: "DocEntry", width: 300, hidden: true },
                            { field: "PromotionID", title: "Promotion", width: 200, hidden: true },
                            { field: "PromotionCode", title: "PromotionCode" , hidden: true},
                            { field: "PromotionName", title: "Promotion", width: 100 },
                            { field: "ItemID", title: "Item", width: 100, hidden: true },
                            { field: "ItemCode", title: "ItemCode", width: 100, hidden: true },
                            { field: "ItemName", title: "ItemName", width: 100 },
                            { field: "Quantity", title: "Quantity", width: 80, attributes: { style: "text-align:right;"}},
                            { field: "BasePrice", title: "BasePrice", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;"} },
                            { field: "DiscountPercent", title: "Discount Percent", width: 80,  attributes: { style: "text-align:right;"} },
                            { field: "DiscountAmount", title: "Discount Amount", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;"} },
                            { field: "PriceAfterDiscount", title: "Price After Discount", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;"} },
                            { field: "TotalAfterDiscount", title: "Total After Discount", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;"} }
                            ],
                edit: function (e) {

                },
                save: function (e) {

                }
            }).data("kendoGrid");
            //Get
            gridGet = $("#gridGet").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "DocPromotion.aspx/GetDocPromotionGet",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        parameterMap: function (data, operation) {
                            if (operation === "read") {
                                return { docEntry: docEntry };
                            }
                        },
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true
                    },
                    type: "odata", //Important!!!!
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d.Data;
                                return data;
                            }
                        },
                        total: "d.Count",
                        model: {
                            id: "Id",
                            fields: {
                                ID: { type: "string", validation: { required: true} },
                                LinkKey: { type: "string", validation: { required: true} },
                                DocEntry: { type: "string", validation: { required: true} },
                                PromotionID: { type: "string", validation: { required: true} },
                                PromotionCode: { type: "string", validation: { required: true} },
                                PromotionName: { type: "string", validation: { required: true} },
                                ItemID: { type: "string", validation: { required: true} },
                                ItemCode: { type: "string", validation: { required: true} },
                                ItemName: { type: "string", validation: { required: true} },
                                Quantity: { type: "number", validation: { required: true} },
                                DiscountPercent: { type: "number", validation: { required: true} },
                                DiscountAmount: { type: "number", validation: { required: true} },
                               // PriceAfterDiscount: { type: "number", validation: { required: true} },
                                TotalAfterDiscount: { type: "number", validation: { required: true} }
                            }
                        }
                    }
                },
                sortable: true,
                filterable: true,
                reorderable: true,
                resizable: true,
                 selectable: "row",
                height: 200,
                excel: {
                    fileName: "Promotion Get List.xlsx",
                    filterable: true
                },
                batch: true,
                columns: [
                            { field: "ID", title: "ID", width: 100, hidden: true },
                            { field: "LinkKey", title: "LinkKey", width: 60, attributes: { style: "text-align:centrer;"} },
                            { field: "DocEntry", title: "DocEntry", width: 300, hidden: true },
                            { field: "PromotionID", title: "Promotion", width: 200, hidden: true },
                            { field: "PromotionCode", title: "PromotionCode" , hidden: true},
                            { field: "PromotionName", title: "Promotion", width: 100 },
                            { field: "ItemID", title: "Item", width: 100, hidden: true },
                            { field: "ItemCode", title: "ItemCode", width: 100, hidden: true },
                            { field: "ItemName", title: "ItemName", width: 100 },
                            { field: "Quantity", title: "Quantity", width: 80, attributes: { style: "text-align:right;"}},
                            { field: "DiscountPercent", title: "Discount Percent", width: 80,  attributes: { style: "text-align:right;"} },
                            { field: "DiscountAmount", title: "Discount Amount", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;"} },
                            //{ field: "PriceAfterDiscount", title: "Price After Discount", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;"} },
                            { field: "TotalAfterDiscount", title: "Total After Discount", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;"} }
                            ],
                edit: function (e) {

                },
                save: function (e) {

                }
            }).data("kendoGrid");
        });
    </script>
    <table width="100%" border="0">
        <tr >
            <td valign="top">
                <span style=" color: #CC3300"><strong><em>BUY</em></strong></span>
            </td>
        </tr>
        <tr>
            <td  valign="top">
                <div id="gridBuy">
                </div>
            </td>
        </tr>
    </table>
    <table width="100%">
        <tr>
            <td  valign="top"><span style=" color: #CC3300"><strong>
                <em>GET</em></strong></span>
            </td>
        </tr>
        <tr>
            <td  valign="top">
                <div id="gridGet">
                </div>
            </td>
        </tr>
    </table>
</asp:Content>
